package com.my_musc_service.controller;

import com.my_musc_service.common.R;
import com.my_musc_service.entity.Favorite;
import com.my_musc_service.entity.FavoriteVO;
import com.my_musc_service.service.FavoriteService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (Favorite)表控制层
 *
 * @author makejava
 * @since 2021-06-10 20:44:45
 * @description 收藏相关
 */
@RestController
@RequestMapping("favorite")
public class FavoriteController {
    /**
     * 服务对象
     */
    @Resource
    private FavoriteService favoriteService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Favorite selectOne(Integer id) {
        return this.favoriteService.queryById(id);
    }

    /**
     * 废弃
     *
     * @param favorite
     * @return
     */
    @Deprecated
    @GetMapping("selectAll")
    public R selectsAll(Favorite favorite) {
        List<Favorite> favoriteList = favoriteService.queryAll(favorite);
        return R.ok().data("favoriteList", favoriteList);
    }

    /**
     * 获取所有收藏歌曲
     * @param favoriteVO
     * @return
     */
    @GetMapping("selectFav")
    public R selectsAllFavSongs(FavoriteVO favoriteVO) {
        Map<String, Object> map = favoriteService.selectAllFavSongs(favoriteVO);
        return R.ok().data(map);
    }


    @PostMapping("add")
    public R addFavorite(@RequestBody Favorite favorite) {
        this.favoriteService.insert(favorite);
        return R.ok();
    }


    @PostMapping("update")
    public R updateFavorite(@RequestBody Favorite favorite) {
        this.favoriteService.update(favorite);
        return R.ok();
    }

    @PostMapping("delete")
    public R deleteFavorite(@RequestBody Favorite favorite) {
        Integer rows = this.favoriteService.delete(favorite);
        return R.ok();
    }
}
